

package com.ifeiyang.bijia.adapter;


import java.util.ArrayList;


import android.annotation.SuppressLint;
import android.opengl.Visibility;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;


import com.ifeiyang.bijia.R;
import com.ifeiyang.bijia.entity.ClusterList;
import com.ifeiyang.bijia.entity.Product;
import com.ifeiyang.bijia.model.App;
import com.ifeiyang.bijia.model.AttrModel;


public class ProductAdapter extends BaseAdapter {


	private AttrModel attrModel;


	public ProductAdapter() {


		attrModel = App.getInstance().getAttrModel();
		inflater = App.getInstance().getInflater();
	}


	@Override
	public int getCount() {


		if (products == null) {
			return 0;
		} else {
			return attrModel.getCount();
		}
	}


	@Override
	public Object getItem(int position) {


		return position;
	}


	@Override
	public long getItemId(int position) {


		return position;
	}


	private LayoutInflater inflater;


	private ArrayList<Product> products;


	private Product product;


	private Product product2;


	@SuppressLint("NewApi")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {


		convertView = inflater.inflate(R.layout.swipe_listview_item, null);


		TextView rowTitle = (TextView) convertView.findViewById(R.id.rowTitle);
		TextView cp1 = (TextView) convertView.findViewById(R.id.cp1);
		TextView cp2 = (TextView) convertView.findViewById(R.id.cp2);
		Button delBtn = (Button) convertView.findViewById(R.id.recent_del_btn);
		delBtn.setVisibility(View.VISIBLE);
//		delBtn.setAlpha(1);
		attrModel.getPosition(position, convertView,rowTitle, cp1, cp2, delBtn, product, product2);

		// if (invisiblePosition >= 0) {
		// if (invisiblePosition == position) {
		// convertView.setVisibility(View.GONE);
		// } else {
		// convertView.setVisibility(View.VISIBLE);
		// }
		//
		// }


		return convertView;
	}


	public void init() {


	}


	public void initData(ClusterList clusterList) {


		this.products = clusterList.getData().getLineList();
		product = products.get(0);
		product2 = products.get(1);
		String concTitle = product.getConcTitle();
		String concTitle2 = product2.getConcTitle();
		if (concTitle == null && concTitle2 == null) {

			attrModel.init(false/* bHasCooc */, this);
		} else {
			attrModel.init(true/* bHasCooc */, this);
		}

	}


	// public void setInvisiblePosition(int invisiblePosition) {
	//
	//
	// this.invisiblePosition = invisiblePosition;
	//
	//
	// }


}
